﻿using System.Text;

namespace DataAccess.Util
{
    public class NameUtils
    {
        /// <summary>
        /// Gets the default column name.
        /// </summary>
        /// <param name="propertyName">the property name</param>
        /// <returns>default column name</returns>
        public static string GetDefaultColumnNameByPropertyName(string propertyName)
        {
            StringBuilder sb = new StringBuilder();
            char[] nameChars = propertyName.ToCharArray();

            for (int i = 0; i < nameChars.Length; i++)
            {
                char c = nameChars[i];

                if (c <= 'Z' && c >= 'A')
                {
                    if (i != 0)
                    {
                        sb.Append("_");
                    }
                }

                sb.Append(c);
            }

            return sb.ToString().ToLower();
        }
    }
}
